package com.rybbaby.tss.front.tssDeposit.service.imp;

import com.google.common.collect.ImmutableMap;
import com.rybbaby.tss.core.utils.StringUtils;
import com.rybbaby.tss.core.web.service.imp.BaseServiceImp;
import com.rybbaby.tss.front.tssDeposit.entity.TssDeposit;
import com.rybbaby.tss.front.tssDeposit.service.ITssDepositService;
import com.rybbaby.tss.front.tssStudent.service.ITssStudentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * @description 订金表数据库操作服务实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-09 下午11:56:55
 */
@Service
@Transactional
public class TssDepositServiceImp extends BaseServiceImp<TssDeposit> implements ITssDepositService {

    @Autowired
    private ITssStudentService tssStudentService;

    /**
     * 新增/修改付订金
     *
     * @param adminUserId
     * @param entity
     */
    @Override
    public boolean saveOrUpdate(String adminUserId, TssDeposit entity) {
        boolean bool=true;
        String id=entity.getId();
        if(StringUtils.isNotBlank(id)){
            TssDeposit destEntity = this.get(id);
            BeanUtils.copyProperties(entity , destEntity ,"createTime");
            this.updateEntitiy(destEntity);
        } else {
            entity.setAdminUserId(adminUserId);
            entity.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis()));
            Serializable newId = this.save(entity);

            //修改客户客户状态为意向强烈
            Integer tssStuId= tssStudentService.updateListStatusOrStatusByIds(ImmutableMap.of(("stuStatus"), 3), null,id);
            if (newId == null && tssStuId == null) {
                return !bool;
            }
        }
        return bool;
    }
}
